home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / misc / bumpseq371.lha / BumpSeq / BumpSeq.c < prev    next >
C/C++ Source or Header  |  1994-12-04  |  2KB  |  129 lines

  1. /****** BumpSeq.c *************************************************************
  2. *
  3. *    $VER: BumpSeq.c 37.1 (4.12.94) -- Copyright © 1994 Magnetic Ink
  4. *
  5. *
  6. *   SYNOPSIS
  7. *        Nothing fancy -- just a quick hack to bump a specified seqFile.
  8. *        SeqFile(s) should be protected by semaphores or lockfiles, but
  9. *        for now I'll make do with this...
  10. *
  11. *   COPYRIGHT
  12. *        BumpSeq and its source are Copyright © 1994 Magnetic Ink, but
  13. *        are freely redistributable for non-profit purposes.
  14. *
  15. *   NOTES
  16. *        Compiled with DICE v3.0
  17. *
  18. *   AUTHOR
  19. *        Snail:
  20. *        ¯¯¯¯¯¯
  21. *        Klaus Alexander Seistrup
  22. *        Ahornsgade 8A¹
  23. *        DK-2200 København N
  24. *        DENMARK
  25. *
  26. *        EMail:
  27. *        ¯¯¯¯¯¯
  28. *        kleis@mink.ping.dk
  29. *
  30. *******************************************************************************/
  31.  
  32. #include "BumpSeq.h"
  33.  
  34.  
  35. /*
  36. **
  37. **    USAGE: BumpSeq <seqFile> [Quiet]
  38. **
  39. */
  40. Prototype LONG     BumpSeq(VOID);
  41. //
  42. LONG
  43. BumpSeq(VOID)
  44. {
  45.     LONG RC = RETURN_FAIL;
  46.  
  47.     LIB *SysBase = *((LIB **)4L);
  48.     LIB *DOSBase = OpenLibrary("dos.library",37L);
  49.  
  50.     if (DOSBase)
  51.     {
  52.         ARG *DObj = (ARG *) AllocDosObject(DOS_RDARGS,NULL);
  53.  
  54.         RC = RETURN_ERROR;
  55.  
  56.         if (DObj)
  57.         {
  58.             ARG  *RDArgs;
  59.             LONG  ArgV[2];
  60.  
  61.             ArgV[0] = ArgV[1] = 0L;
  62.  
  63.             DObj->RDA_ExtHelp = EXTHELP;
  64.             RDArgs = ReadArgs(&(DObj->RDA_ExtHelp[TEMPLATE_OFFS]),ArgV,DObj);
  65.  
  66.             if (RDArgs)
  67.             {
  68.                 TEXT *seqFile = (TEXT *) ArgV[ARG_SEQFILE];
  69.                 BPTR  fh = Open(seqFile,MODE_OLDFILE);
  70.  
  71.                 if (fh == NULL)
  72.                     fh = Open(seqFile,MODE_NEWFILE);
  73.  
  74.                 if (fh == NULL)
  75.                     fh = Open(seqFile,MODE_READWRITE);
  76.  
  77.                 if (fh)
  78.                 {
  79.                     LONG oldVal;
  80.  
  81.                     Seek(fh,0L,OFFSET_BEGINNING);
  82.  
  83.                     if (Read(fh,(TEXT *)&oldVal,4L) != 4L)
  84.                         oldVal = 0L;
  85.  
  86.                     Close(fh);
  87.  
  88.                     if (fh = Open(seqFile,MODE_NEWFILE))
  89.                     {
  90.                         LONG newVal = oldVal + 1L;
  91.  
  92.                         Write(fh,(TEXT *)&newVal,4L);
  93.                         Close(fh);
  94.  
  95.                         if (!ArgV[ARG_QUIET])
  96.                             VPrintf("%ld\n",&oldVal);
  97.  
  98.                         RC = RETURN_OK;
  99.                     }
  100.                     else
  101.                         PrintFault(IoErr(),seqFile);
  102.                 }
  103.                 else
  104.                     PrintFault(IoErr(),seqFile);
  105.  
  106.                 FreeArgs(RDArgs);
  107.             }
  108.             else
  109.                 PrintFault(IoErr(),NULL);
  110.  
  111.             FreeDosObject(DOS_RDARGS,DObj);
  112.         }
  113.         else
  114.             PrintFault(ERROR_NO_FREE_STORE,NULL);
  115.  
  116.         CloseLibrary(DOSBase);
  117.     }
  118.     return (RC);
  119. }
  120.  
  121. STXT VersTag[]        = "$VER: " VSTR;
  122. STXT Compiled[]        = "Compiled on " __DATE__ " at " __TIME__;
  123. STXT Copyright[]    = "Copyright © 1994 Klaus Alexander Seistrup @ Magnetic Ink";
  124. STXT EMail[]        = "E-mail: kleis@mink.ping.dk";
  125.  
  126. /*
  127. **    EOF
  128. */
  129.